<?php

namespace App\Models\Product;

use Illuminate\Database\Eloquent\Model;

class Product extends Model
{
    protected $table = 'zlg_product';

    protected $casts = [
        'created_at' => 'datetime:Y-m-d H:i:s',
        'updated_at' => 'datetime:Y-m-d H:i:s',
    ];
    //获取所有商品
    public function getAllProduct($param)
    {
        $pageSize = $param['size'] ?? 10;
        return $this->leftJoin('zlg_category as c','p.category_id','=','c.id')
        ->from('zlg_product as p')
        ->orderBy("p.id","desc")
        ->select("p.*","c.name as category_name")
        ->paginate($pageSize);
    }

    public function getProduct($id)
    {
        return $this->where('id','=',$id)->first();
    }

    public function updateds($id,$data)
    {
        $res=$this->where('id','=',$id)->update($data);
        if($res){
            return true;
        }
        return false;
    }

}
